/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aletex.ui;

import aletex.da.UserFacade;
import aletex.entity.User;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author cibervn
 */
@ManagedBean
@ViewScoped
public class UserController {

    /**
     * List all user from database
     */
    private List<User> list;
    /**
     * user to work:insert, delete or update
     */
    private User current;
    /**
     * to work to db
     *
     */
    @EJB
    private UserFacade userJpa;
    /**
     * if data is change
     */
    private boolean changed = true;

    /**
     * Creates a new instance of UserController
     */
    public UserController() {
    }

    public List<User> getList() {
        if (list == null || changed) {
            list = userJpa.findAll();
        }
        return list;
    }

    public User getCurrent() {
        if (current == null) {
            current = new User();
        }
        return current;
    }
}
